<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use Mews\Captcha\Facades\Captcha;

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/

Route::group(['middleware' => ['web']], function () {

    Route::get('login', 'Auth\AuthController@getLogin');
    Route::post('login', 'Auth\AuthController@postLogin');
    Route::get('logout', 'Auth\AuthController@logout');
    Route::post('password/reset', 'Auth\PasswordController@reset');
    Route::post('avatar', 'Setting\UserController@avatar');
    Route::get('version/{id}', 'Version\VersionController@list');

    Route::get('captcha', function(Request $request) {
        return Captcha::create();
    });
});

Route::group(['middleware' => ['web' , 'acl']], function () {

    Route::get('/', function (Request $request) {

        header("Location: /home");exit;
    });

    Route::get('/home', function (Request $request) {

        return view("home/index")->with('request', $request);
    });

    foreach (\App\Http\Route::label() as $label) {
        foreach ($label as $item) {
            Route::get($item['uri'], $item['action']);

            foreach ($item['ajax'] as $ajax) {
                $method = $ajax['method'];
                Route::$method($ajax['uri'], $ajax['action']);
            }
        }
    }
});
